﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatLoaiVanBan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaLoaiVanBan();

            layTenLoaiVanBan();
        }
    }

    protected void layMaLoaiVanBan()
    {
        string maLoaiVanBanURL = Request.QueryString["MaLoaiVanBan"];

        LoaiVanBanBUS lvbBUS = new LoaiVanBanBUS();

        string maLoaiVanBan = lvbBUS.layMaLoaiVanBan(maLoaiVanBanURL);

        txtMaLoaiVanBan.Text = maLoaiVanBan;
    }

    protected void layTenLoaiVanBan()
    {
        string maLoaiVanBanURL = Request.QueryString["MaLoaiVanBan"];

        LoaiVanBanBUS lvbBUS = new LoaiVanBanBUS();

        string tenLoaiVanBan = lvbBUS.layTenLoaiVanBan(maLoaiVanBanURL);

        txtTenLoaiVanBan.Text = tenLoaiVanBan;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            LoaiVanBan lvbDTO = new LoaiVanBan();
            lvbDTO.MaLoaiVanBan = txtMaLoaiVanBan.Text.ToUpper();
            lvbDTO.TenLoaiVanBan = txtTenLoaiVanBan.Text.ToUpper();

            //Kiem tra rong
            if (lvbDTO.MaLoaiVanBan.ToString() == string.Empty)
            {
                Alert.Show("Ma loai van ban khong duoc rong");
                return;
            }

            if (lvbDTO.TenLoaiVanBan.ToString() == string.Empty)
            {
                Alert.Show("Ten loai van ban khong duoc rong");
                return;
            }

            //Sua
            if (lvbDTO.MaLoaiVanBan.ToString() != string.Empty && lvbDTO.TenLoaiVanBan.ToString() != string.Empty)
            {
                LoaiVanBanBUS lvbBUS = new LoaiVanBanBUS();

                string maLoaiVanBanURL = Request.QueryString["MaLoaiVanBan"];

                lvbBUS.suaLoaiVanBan(lvbDTO, maLoaiVanBanURL);

                Response.Redirect("ThamSoVanBan.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoVanBan.aspx");
    }
}